﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace TSPquestEDITOR
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            string connectionString =
                //Set connectionString
            connectionString = string.Format("user id=sa;" +
            "password=shadowMASTER2501;server=46.129.78.244;" +
            "Trusted_Connection=no;" +
            "database=teal_sky_arcadia_test; " +
            "connection timeout=30");


            string search_name = basic_info.multi_quest_search_name;

            //Define Connection
            SqlConnection qCon = new SqlConnection(connectionString);
            //Open Connection
            qCon.Open();

            string strSQL = "SELECT QRES.id, SRES.value as name, QRES.limit_level as 'Level Req' FROM dbo.StringResource SRES INNER JOIN dbo.QuestResource QRES on QRES.text_id_quest = SRES.code";

            SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, qCon);
            SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

            // Populate a new data table and bind it to the BindingSource.
            DataTable table = new DataTable();
            table.Locale = System.Globalization.CultureInfo.InvariantCulture;
            dataAdapter.Fill(table);
            bindSource.DataSource = table;

            // Resize the DataGridView columns to fit the newly loaded content.
            dgv.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.Fill);
            // you can make it grid readonly.
            dgv.ReadOnly = true;
            // finally bind the data to the grid
            dgv.DataSource = bindSource;
        }

        private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = dgv.CurrentCell.OwningRow;
            string returned_val = row.Cells["id"].Value.ToString();
            basic_info.multi_quest_search_return_id = returned_val.ToString();

            this.Dispose();
        }
    }
}
